package com.bysj.yqsht.web.controller;


import com.bysj.yqsht.bean.Activity;
import com.bysj.yqsht.bean.extend.ActivityExtend;
import com.bysj.yqsht.service.IActivityService;
import com.bysj.yqsht.utils.Message;
import com.bysj.yqsht.utils.MessageUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/activity")
@Api(description = "活动管理接口")
public class ActivityController {
    @Resource
    private IActivityService activityService;

    @GetMapping("findAll")
    public Message findAll(){
        List<Activity> activities = activityService.findAll();
        return MessageUtil.success(activities);
    }
    @GetMapping("findWithAll")
    public Message findWithAll(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int limit){
        List<ActivityExtend> list = activityService.findWithAll(pageNum,limit);
        return MessageUtil.success(list);
    }
    @GetMapping("findWithAllBy")
    public Message findWithAllBy(String name,String classId){
        List<ActivityExtend> list = activityService.findWithAllBy(name,classId);
        return MessageUtil.success(list);
    }
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Activity activity){
        activityService.saveOrUpdate(activity);
        return MessageUtil.success("新增或修改成功");
    }
    @GetMapping("deleteById")
    public Message deleteById(long id){
        activityService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
}
